<?php
session_start();
function DoLogin($email, $password)
{
        $sql = "
                SELECT U.id, password, FirstName, LastName
                FROM Users U
                        Join ContactMethods CM On U.id=CM.User_Id
                WHERE CM.`Value` = '$email'
                ";
        $conn = getConnection();
        $result = $conn->query($sql);
        $rs = $result->fetch_assoc();
        $conn->close();
        if($rs['password'] == $password)
        {
                $_SESSION['UserId'] = $rs['id'];
                $_SESSION['UserEmail'] = $email;
                $_SESSION['UserName'] = $rs['FirstName'] . ' ' . $rs['LastName'];
        }
}
function IsLoggedIn()
{
        return isset($_SESSION['UserId']);
}
function GetUserName()
{
        return $_SESSION['UserName'];
}
function GetUserId()
{
        return $_SESSION['UserId'];
}
function GetUserEmail()
{
        return $_SESSION['UserEmail'];
}
function DoLogOut()
{
        session_destroy();
}
?>